package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.MdBaseDictItemService;
import com.dw.etl.core.mapper.MdBaseDictItemMapper;
import com.dw.etl.core.bean.model.MdBaseDictItem;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * mdBaseDictItem服务实现类
 * Created by hozeData on 2021/07/13.
 */
@Service
@Transactional
public class MdBaseDictItemServiceImpl implements MdBaseDictItemService{

    private static final Logger LOGGER = LoggerFactory.getLogger(MdBaseDictItemServiceImpl.class);

    @Autowired
    private MdBaseDictItemMapper mdBaseDictItemMapper;

    @Override
    public int insert(MdBaseDictItem mdBaseDictItem) {
        if(StringUtils.isEmpty(mdBaseDictItem.getIdDictItem())){
            String uuid32 = UUIDUtil.getUUID32();
            mdBaseDictItem.setIdDictItem(uuid32);
        }
        return mdBaseDictItemMapper.insert(mdBaseDictItem);
    }

    @Override
    public int insertSelective(MdBaseDictItem mdBaseDictItem)  {
        if(StringUtils.isEmpty(mdBaseDictItem.getIdDictItem())){
            String uuid32 = UUIDUtil.getUUID32();
            mdBaseDictItem.setIdDictItem(uuid32);
        }
        return mdBaseDictItemMapper.insertSelective(mdBaseDictItem);
    }

    @Override
    public int deleteById(String idDictItem)  {
        return mdBaseDictItemMapper.deleteByPrimaryKey(idDictItem);
    }

    @Override
    public int updateByIdSelective(MdBaseDictItem mdBaseDictItem)  {

        return mdBaseDictItemMapper.updateByPrimaryKeySelective(mdBaseDictItem);
    }

    @Override
    public int updateById(MdBaseDictItem mdBaseDictItem)  {
        return mdBaseDictItemMapper.updateByPrimaryKey(mdBaseDictItem);
    }

    @Override
    public MdBaseDictItem getById(String idDictItem)  {
        return mdBaseDictItemMapper.selectByPrimaryKey(idDictItem);
    }

    @Override
    public List<MdBaseDictItem> findByModel(MdBaseDictItem mdBaseDictItem)  {
        return mdBaseDictItemMapper.findByModel(mdBaseDictItem);
    }

    @Override
    public PaginationVO<MdBaseDictItem> findPageByModel(MdBaseDictItem mdBaseDictItem, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<MdBaseDictItem> quesList = mdBaseDictItemMapper.findByModel(mdBaseDictItem);
        PageInfo<MdBaseDictItem> pageInfo = new PageInfo<>(quesList);
        PaginationVO<MdBaseDictItem> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }





}
